#!/usr/bin/env python
# coding: utf-8

# In[1]:


import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import math
from scipy.stats import skew
from matplotlib.lines import Line2D


# In[2]:


df = pd.read_csv("D:/research/recordbreak/rb_count10.csv")
print(df)


# In[3]:


# Extracting data for each river
indus_data = df[['indus70','indus10', 'indus50', 'indus90']]
kabul_data = df[['kabul70','kabul10', 'kabul50', 'kabul90']]
jehlum_data = df[['jehlum70','jehlum10', 'jehlum50', 'jehlum90']]
chenab_data= df[['chenab70','chenab10', 'chenab50', 'chenab90']]

# Calculate mean, min, and max values for each river and each RCP
def calculate_values(data):
    rcp_45_values = data[df['var'].str.contains('dry_min45')]
    rcp_85_values = data[df['var'].str.contains('dry_min85')]

    mean_values_45 = rcp_45_values.mean()
    min_values_45 = rcp_45_values.min()
    max_values_45 = rcp_45_values.max()

    mean_values_85 = rcp_85_values.mean()
    min_values_85 = rcp_85_values.min()
    max_values_85 = rcp_85_values.max()

    return (mean_values_45, min_values_45, max_values_45), (mean_values_85, min_values_85, max_values_85)

# Calculate values for each river
indus_values = calculate_values(indus_data)
kabul_values = calculate_values(kabul_data)
jehlum_values = calculate_values(jehlum_data)
chenab_values = calculate_values(chenab_data)


# Plotting all rivers in one graph
fig, ax = plt.subplots(figsize=(18, 9)) 
x_offset=0.3
# Plotting Indus River
ax.errorbar(['indus70','indus10', 'indus50', 'indus90'], indus_values[0][0], 
            yerr=[indus_values[0][0] - indus_values[0][1], indus_values[0][2] - indus_values[0][0]],
            fmt='d', label='Indus - RCP 4.5', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['indus70','indus10', 'indus50', 'indus90'], indus_values[1][0], 
            yerr=[indus_values[1][0] - indus_values[1][1], indus_values[1][2] - indus_values[1][0]],
            fmt='o', label='Kabul - RCP 8.5', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Plotting Kabul River
ax.errorbar(['kabul70','kabul10', 'kabul50', 'kabul90'], kabul_values[0][0], 
            yerr=[kabul_values[0][0] - kabul_values[0][1], kabul_values[0][2] - kabul_values[0][0]],
            fmt='d', label='Kabul - RCP 4.5', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['kabul70','kabul10', 'kabul50', 'kabul90'], kabul_values[1][0], 
            yerr=[kabul_values[1][0] - kabul_values[1][1], kabul_values[1][2] - kabul_values[1][0]],
            fmt='o', label='Kabul - RCP 8.5', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Plotting Jehlum River
ax.errorbar(['jehlum70','jehlum10', 'jehlum50', 'jehlum90'], jehlum_values[0][0], 
            yerr=[jehlum_values[0][0] - jehlum_values[0][1], jehlum_values[0][2] - jehlum_values[0][0]],
            fmt='d', label='Jehlum - RCP 4.5', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['jehlum70','jehlum10', 'jehlum50', 'jehlum90'], jehlum_values[1][0], 
            yerr=[jehlum_values[1][0] - jehlum_values[1][1], jehlum_values[1][2] - jehlum_values[1][0]],
            fmt='o', label='Jehlum - RCP 8.5', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Plotting Chenab River
ax.errorbar(['chenab70','chenab10', 'chenab50', 'chenab90'], chenab_values[0][0], 
            yerr=[chenab_values[0][0] - chenab_values[0][1], chenab_values[0][2] - chenab_values[0][0]],
            fmt='d', label='Chenab - RCP 4.5', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['chenab70','chenab10', 'chenab50', 'chenab90'], chenab_values[1][0], 
            yerr=[chenab_values[1][0] - chenab_values[1][1], chenab_values[1][2] - chenab_values[1][0]],
            fmt='o', label='Chenab - RCP 8.5', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)


# Adding vertical lines between rivers
ax.axvline(x=3.5, color='gray', linestyle='--', linewidth=2)  # Between Indus and Jehlum
ax.axvline(x=7.5, color='gray', linestyle='--', linewidth=2)  # Between Jehlum and Chenab
ax.axvline(x=11.5, color='gray', linestyle='--', linewidth=2)  # Between Chenab and Kabul

#ax.set_xlabel('Years (2023, 2050, 2098)')  # Adjust the x-axis label
ax.set_ylabel('Probability Ratio', fontsize=20, fontweight='bold')
#ax.set_title('Error Bar Plot for River Scenarios')
handles, labels = ax.get_legend_handles_labels()
# Selecting and adjusting the legend entries for RCP 4.5 and RCP 8.5
ax.legend([handles[0], handles[3]], ['RCP 4.5', 'RCP 8.5'], loc='upper left', prop={'size': 20, 'weight': 'bold'})  # Manually setting legend labels

years = ['1','2', '3', '4'] * 4  # Years repeated for the number of river groups
ax.set_xticks(range(len(years)))  # Setting positions for the ticks
ax.set_xticklabels(years, rotation=0, fontsize=16, weight='bold')  # Setting custom labels for the primary x-axis

#river_names = [None, 'Indus', None, None, 'Jehlum', None, None, 'Chenab',None,  'Kabul' ]  # River names repeated for the number of years
#river_positions = [1.5, 4.75, 7.5, 11.75]  # Midpoints between each pair of years for centering the river names
#ax2 = ax.twiny()
#ax2.set_xticks(river_positions)  # Setting positions for the ticks based on river names' midpoints
#ax2.set_xticklabels([name for name in river_names if name is not None])  # Setting custom labels for the secondary x-axis (top)
#ax2.xaxis.tick_top()  # Placing the secondary x-axis at the top
ax.tick_params(axis='x', labelsize=22, width=4, length=12)
ax.tick_params(axis='y', labelsize=22, width=4, length=12)
ax.set_ylim(1, 16)
ax.tick_params(axis='y', labelsize=22)
for label in ax.yaxis.get_ticklabels():
    label.set_fontweight('bold')
plt.tight_layout()
#boundry thickness
ax = plt.gca()
for spine in ax.spines.values():
    spine.set_linewidth(4)
ax.yaxis.grid(True, linestyle='--', linewidth=1) 
plt.show()


# # Fig 4C

# In[4]:


fig, ax = plt.subplots(figsize=(20, 10)) 
x_offset = 0.3

# Plotting Indus River
ax.errorbar(['indus70', 'indus10', 'indus50', 'indus90'], indus_values[0][0], 
            yerr=[indus_values[0][0] - indus_values[0][1], indus_values[0][2] - indus_values[0][0]],
            fmt='d', label='Indus - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
ind_values = np.arange(len(['indus70', 'indus10', 'indus50', 'indus90']))
shifted_ind = ind_values + x_offset
shift_ind = ind_values -0.3
ax.errorbar(shifted_ind, indus_values[1][0], 
            yerr=[indus_values[1][0] - indus_values[1][1], indus_values[1][2] - indus_values[1][0]],
            fmt='o', label='Indus - RCP 8.5', color='red', alpha=0.8,linewidth=6, markersize=26,elinewidth=4)
ind_obs = (2, 4,-5,-5)  # Modify this line with the actual observational values
ax.scatter(shift_ind, ind_obs, marker='s',  color='black', s=400)

# Plotting Kabul River
ax.errorbar(['kabul70', 'kabul10', 'kabul50', 'kabul90'], kabul_values[0][0], 
            yerr=[kabul_values[0][0] - kabul_values[0][1], kabul_values[0][2] - kabul_values[0][0]],
            fmt='d', label='Kabul - RCP 4.5', color='teal', alpha=0.8,linewidth=6, markersize=26,elinewidth=6)
kab_values = np.arange(len(['kabul70', 'kabul10', 'kabul50', 'kabul90']))
shifted_kab = kab_values + 4.2
shift_kab = kab_values + 3.7
ax.errorbar(shifted_kab, kabul_values[1][0], 
            yerr=[kabul_values[1][0] - kabul_values[1][1], kabul_values[1][2] - kabul_values[1][0]],
            fmt='o', label='Kabul - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
kab_obs = (2, 4,-5,-5)  # Modify this line with the actual observational values
ax.scatter(shift_kab, kab_obs, marker='s',  color='black', s=400)

# Plotting Jehlum River
ax.errorbar(['jehlum70', 'jehlum10', 'jehlum50', 'jehlum90'], jehlum_values[0][0], 
            yerr=[jehlum_values[0][0] - jehlum_values[0][1], jehlum_values[0][2] - jehlum_values[0][0]],
            fmt='d', label='Jehlum - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

jeh_values = np.arange(len(['jehlum70', 'jehlum10', 'jehlum50', 'jehlum90']))
shifted_jeh = jeh_values + 8.3
shift_jeh = jeh_values + 7.7
ax.errorbar(shifted_jeh, jehlum_values[1][0], 
            yerr=[jehlum_values[1][0] - jehlum_values[1][1], jehlum_values[1][2] - jehlum_values[1][0]],
            fmt='o', label='Jehlum - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
jeh_obs = (4.7, 7.3,-5,-5)  # Modify this line with the actual observational values
ax.scatter(shift_jeh, jeh_obs, marker='s',  color='black', s=400)
# Plotting Chenab River
ax.errorbar(['chenab70', 'chenab10', 'chenab50', 'chenab90'], chenab_values[0][0], 
            yerr=[chenab_values[0][0] - chenab_values[0][1], chenab_values[0][2] - chenab_values[0][0]],
            fmt='d', label='Chenab - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

che_values = np.arange(len(['chenab70', 'chenab10', 'chenab50', 'chenab90']))
shifted_che = che_values + 12.3
shift_che = che_values + 11.7
ax.errorbar(shifted_che, chenab_values[1][0], 
            yerr=[chenab_values[1][0] - chenab_values[1][1], chenab_values[1][2] - chenab_values[1][0]],
            fmt='o', label='Chenab - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
che_obs = (3, 4,-5,-5)  # Modify this line with the actual observational values
ax.scatter(shift_che, che_obs, marker='s',  color='black', s=400)
# Adding vertical lines between rivers
ax.axvline(x=3.5, color='gray', linestyle='--', linewidth=2)  # Between Indus and Jehlum
ax.axvline(x=7.45, color='gray', linestyle='--', linewidth=2)  # Between Jehlum and Chenab
ax.axvline(x=11.5, color='gray', linestyle='--', linewidth=2)  # Between Chenab and Kabul

#ax.set_xlabel('Years (2023, 2050, 2098)')  # Adjust the x-axis label
#ax.set_ylabel('Probability Ratio', fontsize=40) #, fontweight='bold' , fontname='Times New Roman'
#ax.set_title('Error Bar Plot for River Scenarios')
handles, labels = ax.get_legend_handles_labels()
# Selecting and adjusting the legend entries for RCP 4.5 and RCP 8.5
handles, labels = ax.get_legend_handles_labels()
obs_legend = Line2D([0], [0], marker='s', color='w', markerfacecolor='black', markersize=24)
#legend = ax.legend([obs_legend, handles[0], handles[3]], ['Observed', 'RCP 4.5', 'RCP 8.5'], loc='upper right', prop={'size': 36})
#legend.get_frame().set_linewidth(4)
#legend.get_frame().set_edgecolor('black')
years = ['1970s','2010s', '2050s', '2090s'] * 4  # Years repeated for the number of river groups
ax.set_xticks(range(len(years)))  # Setting positions for the ticks
ax.set_xticklabels(years, rotation=90, fontsize=40)  # , weight='bold' Setting custom labels for the primary x-axis

ax.tick_params(axis='x', labelsize=40, width=4, length=18)
ax.tick_params(axis='y', labelsize=30, width=4, length=18)
ax.set_ylim(-0.9, 17)
ax.set_xlim(-0.5, 15.6)
ax.tick_params(axis='y', labelsize=36)
#for label in ax.yaxis.get_ticklabels():
    #label.set_fontweight('bold')
plt.tight_layout()
#boundry thickness
ax = plt.gca()
for spine in ax.spines.values():
    spine.set_linewidth(4)
ax.yaxis.grid(True, linestyle='--', linewidth=1) 
plt.show()


# In[ ]:





# # Fig 4b

# # Wetting Scenario

# In[5]:


# Extracting data for each river for the 'wet' scenario
indus_data_wet = df[['indus70','indus10', 'indus50', 'indus90']]
kabul_data_wet = df[['kabul70','kabul10', 'kabul50', 'kabul90']]
jehlum_data_wet = df[['jehlum70','jehlum10', 'jehlum50', 'jehlum90']]
chenab_data_wet = df[['chenab70','chenab10', 'chenab50', 'chenab90']]

# Calculate mean, min, and max values for each river and each RCP - Wet scenario
def calculate_values_wet(data):
    rcp_45_values_wet = data[df['var'].str.contains('wet_max45')]
    rcp_85_values_wet = data[df['var'].str.contains('wet_max85')]

    mean_values_45_wet = rcp_45_values_wet.mean()
    min_values_45_wet = rcp_45_values_wet.min()
    max_values_45_wet = rcp_45_values_wet.max()

    mean_values_85_wet = rcp_85_values_wet.mean()
    min_values_85_wet = rcp_85_values_wet.min()
    max_values_85_wet = rcp_85_values_wet.max()

    return (mean_values_45_wet, min_values_45_wet, max_values_45_wet), (mean_values_85_wet, min_values_85_wet, max_values_85_wet)

# Calculate values for each river - Wet scenario
indus_values_wet = calculate_values_wet(indus_data_wet)
jehlum_values_wet = calculate_values_wet(jehlum_data_wet)
chenab_values_wet = calculate_values_wet(chenab_data_wet)
kabul_values_wet = calculate_values_wet(kabul_data_wet)

# Plotting for the 'wet' scenarios
fig, ax = plt.subplots(figsize=(16, 9))
# Plotting Indus River for 'wet' scenarios
ax.errorbar(['indus70','indus10', 'indus50', 'indus90'], indus_values_wet[0][0], 
            yerr=[indus_values_wet[0][0] - indus_values_wet[0][1], indus_values_wet[0][2] - indus_values_wet[0][0]],
            fmt='d', label='Indus - RCP 4.5 (Wet)', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['indus70','indus10', 'indus50', 'indus90'], indus_values_wet[1][0], 
            yerr=[indus_values_wet[1][0] - indus_values_wet[1][1], indus_values_wet[1][2] - indus_values_wet[1][0]],
            fmt='o', label='Indus - RCP 8.5 (Wet)', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Plotting Kabul River for 'wet' scenarios
ax.errorbar(['kabul70','kabul10', 'kabul50', 'kabul90'], kabul_values_wet[0][0], 
            yerr=[kabul_values_wet[0][0] - kabul_values_wet[0][1], kabul_values_wet[0][2] - kabul_values_wet[0][0]],
            fmt='d', label='Kabul - RCP 4.5 (Wet)', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['kabul70','kabul10', 'kabul50', 'kabul90'], kabul_values_wet[1][0], 
            yerr=[kabul_values_wet[1][0] - kabul_values_wet[1][1], kabul_values_wet[1][2] - kabul_values_wet[1][0]],
            fmt='o', label='Kabul - RCP 8.5 (Wet)', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Plotting Jehlum River for 'wet' scenarios
ax.errorbar(['jehlum70','jehlum10', 'jehlum50', 'jehlum90'], jehlum_values_wet[0][0], 
            yerr=[jehlum_values_wet[0][0] - jehlum_values_wet[0][1], jehlum_values_wet[0][2] - jehlum_values_wet[0][0]],
            fmt='d', label='Jehlum - RCP 4.5 (Wet)', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['jehlum70','jehlum10', 'jehlum50', 'jehlum90'], jehlum_values_wet[1][0], 
            yerr=[jehlum_values_wet[1][0] - jehlum_values_wet[1][1], jehlum_values_wet[1][2] - jehlum_values_wet[1][0]],
            fmt='o', label='jehlum - RCP 8.5 (Wet)', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Plotting Chenab River for 'wet' scenarios
ax.errorbar(['chenab70','chenab10', 'chenab50', 'chenab90'], chenab_values_wet[0][0], 
            yerr=[chenab_values_wet[0][0] - chenab_values_wet[0][1], chenab_values_wet[0][2] - chenab_values_wet[0][0]],
            fmt='d', label='Chenab - RCP 4.5 (Wet)', color='teal',alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['chenab70','chenab10', 'chenab50', 'chenab90'], chenab_values_wet[1][0], 
            yerr=[chenab_values_wet[1][0] - chenab_values_wet[1][1], chenab_values_wet[1][2] - chenab_values_wet[1][0]],
            fmt='o', label='Chenab - RCP 8.5 (Wet)', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Adding vertical lines between rivers (same as previous code)

# Adding vertical lines between rivers
ax.axvline(x=3.5, color='gray', linestyle='--', linewidth=2)  # Between Indus and Jehlum
ax.axvline(x=7.5, color='gray', linestyle='--', linewidth=2)  # Between Jehlum and Chenab
ax.axvline(x=11.5, color='gray', linestyle='--', linewidth=2)  # Between Chenab and Kabul

#ax.set_xlabel('Years (2023, 2050, 2098)')  # Adjust the x-axis label
ax.set_ylabel('Probability Ratio', fontsize=20, fontweight='bold')
#ax.set_title('Error Bar Plot for River Scenarios')
handles, labels = ax.get_legend_handles_labels()
# Selecting and adjusting the legend entries for RCP 4.5 and RCP 8.5
ax.legend([handles[0], handles[3]], ['RCP 4.5', 'RCP 8.5'], loc='upper left', prop={'size': 20, 'weight': 'bold'}) #Manually setting legend labels

#years = ['2023', '2050', '2098'] * 4  # Years repeated for the number of river groups
ax.set_xticks(range(len(years)))  # Setting positions for the ticks
ax.set_xticklabels(years, rotation=90, fontsize=16, weight='bold') # Setting custom labels for the primary x-axis

#river_names = [None, 'Indus', None, None, 'Jehlum', None, None, 'Chenab',None,  'Kabul' ]  # River names repeated for the number of years
#river_positions = [1.5, 4.75, 7.5, 11.75]  # Midpoints between each pair of years for centering the river names
#ax2 = ax.twiny()
#ax2.set_xticks(river_positions)  # Setting positions for the ticks based on river names' midpoints
#ax2.set_xticklabels([name for name in river_names if name is not None])  # Setting custom labels for the secondary x-axis (top)
#ax2.xaxis.tick_top()  # Placing the secondary x-axis at the top
ax.tick_params(axis='x', labelsize=22, width=4, length=12)
ax.tick_params(axis='y', labelsize=22, width=4, length=12)
ax.set_ylim(1, 17)
ax.tick_params(axis='y', labelsize=22)
for label in ax.yaxis.get_ticklabels():
    label.set_fontweight('bold')
plt.tight_layout()
#boundry thickness
ax = plt.gca()
for spine in ax.spines.values():
    spine.set_linewidth(4)
#gridlines
ax.yaxis.grid(True, linestyle='--', linewidth=1) 
plt.show()


# In[6]:


fig, ax = plt.subplots(figsize=(20, 10))
x_offset = 0.2 
# Plotting Indus River for 'wet' scenarios
ax.errorbar(['indus70','indus10', 'indus50', 'indus90'], indus_values_wet[0][0], 
            yerr=[indus_values_wet[0][0] - indus_values_wet[0][1], indus_values_wet[0][2] - indus_values_wet[0][0]],
            fmt='d', label='Indus - RCP 4.5 (Wet)', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

ind_values = np.arange(len(['indus70','indus10', 'indus50', 'indus90']))
shifted_ind = ind_values + x_offset
shift_ind=ind_values - 0.3

ax.errorbar(shifted_ind, indus_values_wet[1][0], 
            yerr=[indus_values_wet[1][0] - indus_values_wet[1][1], indus_values_wet[1][2] - indus_values_wet[1][0]],
            fmt='o', label='Indus - RCP 8.5 (Wet)', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

ind_obs = (4, 6,-5,-5)  # Modify this line with the actual observational values
ax.scatter(shift_ind, ind_obs, marker='s',  color='black', s=400)

# Plotting Kabul River for 'wet' scenarios
ax.errorbar(['kabul70','kabul10', 'kabul50', 'kabul90'], kabul_values_wet[0][0], 
            yerr=[kabul_values_wet[0][0] - kabul_values_wet[0][1], kabul_values_wet[0][2] - kabul_values_wet[0][0]],
            fmt='d', label='Kabul - RCP 4.5 (Wet)', color='teal', alpha=0.8,linewidth=6, markersize=26,elinewidth=6)

kabul_values = np.arange(len(['kabul70','kabul10', 'kabul50', 'kabul90']))
shifted_kabul = kabul_values + 4.3
shift_kabul = kabul_values + 3.7
ax.errorbar(shifted_kabul, kabul_values_wet[1][0], 
            yerr=[kabul_values_wet[1][0] - kabul_values_wet[1][1], kabul_values_wet[1][2] - kabul_values_wet[1][0]],
            fmt='o', label='Kabul - RCP 8.5 (Wet)', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

kab_obs = (5, 7,-5,-5)  # Modify this line with the actual observational values
ax.scatter(shift_kabul, kab_obs, marker='s',  color='black', s=400)

# Plotting Jehlum River for 'wet' scenarios
ax.errorbar(['jehlum70','jehlum10', 'jehlum50', 'jehlum90'], jehlum_values_wet[0][0], 
            yerr=[jehlum_values_wet[0][0] - jehlum_values_wet[0][1], jehlum_values_wet[0][2] - jehlum_values_wet[0][0]],
            fmt='d', label='Jehlum - RCP 4.5 (Wet)', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
jehlum_values = np.arange(len(['jehlum70','jehlum10', 'jehlum50', 'jehlum90']))
shifted_jehlum = jehlum_values + 8.3
shift_jehlum = jehlum_values + 7.7
ax.errorbar(shifted_jehlum, jehlum_values_wet[1][0], 
            yerr=[jehlum_values_wet[1][0] - jehlum_values_wet[1][1], jehlum_values_wet[1][2] - jehlum_values_wet[1][0]],
            fmt='o', label='Jehlum - RCP 8.5 (Wet)', color='red', alpha=0.8,linewidth=6, markersize=26,elinewidth=6)
jeh_obs = (4.4, 6,-5,-5)  # Modify this line with the actual observational values
ax.scatter(shift_jehlum, jeh_obs, marker='s', color='black', s=400)

# Plotting Chenab River for 'wet' scenarios
ax.errorbar(['chenab70','chenab10', 'chenab50', 'chenab90'], chenab_values_wet[0][0], 
            yerr=[chenab_values_wet[0][0] - chenab_values_wet[0][1], chenab_values_wet[0][2] - chenab_values_wet[0][0]],
            fmt='d', label='Chenab - RCP 4.5 (Wet)', color='teal',alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
chenab_values = np.arange(len(['chenab70','chenab10', 'chenab50', 'chenab90']))
shifted_chenab = chenab_values + 12.2
shift_chenab = chenab_values + 11.7
ax.errorbar(shifted_chenab, chenab_values_wet[1][0], 
            yerr=[chenab_values_wet[1][0] - chenab_values_wet[1][1], chenab_values_wet[1][2] - chenab_values_wet[1][0]],
            fmt='o', label='Chenab - RCP 8.5 (Wet)', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
che_obs = (4.1, 7,-5,-5)  # Modify this line with the actual observational values
ax.scatter(shift_chenab, che_obs, marker='s',color='black', s=400)

# Adding vertical lines between rivers (same as previous code)

# Adding vertical lines between rivers
ax.axvline(x=3.5, color='gray', linestyle='--', linewidth=2)  # Between Indus and Jehlum
ax.axvline(x=7.5, color='gray', linestyle='--', linewidth=2)  # Between Jehlum and Chenab
ax.axvline(x=11.5, color='gray', linestyle='--', linewidth=2)  # Between Chenab and Kabul

#ax.set_xlabel('Years (2023, 2050, 2098)')  # Adjust the x-axis label
#ax.set_ylabel('Probability Ratio', fontsize=40) #, fontweight='bold'
#ax.set_title('Error Bar Plot for River Scenarios')
handles, labels = ax.get_legend_handles_labels()
# Selecting and adjusting the legend entries for RCP 4.5 and RCP 8.5
#ax.legend([handles[0], handles[3]], ['RCP 4.5', 'RCP 8.5'], loc='upper left', prop={'size': 36})  # , 'weight': 'bold'Manually setting legend labels

years = ['1970s','2010s', '2050s', '2090s'] * 4  # Years repeated for the number of river groups
ax.set_xticks(range(len(years)))  # Setting positions for the ticks
ax.set_xticklabels(years, rotation=90, fontsize=40)  # , weight='bold' Setting custom labels for the primary x-axis

ax.tick_params(axis='x', labelsize=40, width=4, length=18)
ax.tick_params(axis='y', labelsize=30, width=4, length=18)
ax.set_ylim(-0.9, 18)
ax.set_xlim(-0.5, 15.5)
ax.tick_params(axis='y', labelsize=36)
#for label in ax.yaxis.get_ticklabels():
    #label.set_fontweight('bold')
plt.tight_layout()
#boundry thickness
ax = plt.gca()
for spine in ax.spines.values():
    spine.set_linewidth(4)
ax.yaxis.grid(True, linestyle='--', linewidth=1) 
plt.show()


# In[ ]:





# In[ ]:





# In[ ]:





# In[ ]:




